var isMusicOn = false;
cc.Class({
    extends: cc.Component,

    properties: {
        audioMng: cc.Node,
        btnMusic: cc.Sprite,
        texMusicOn: cc.SpriteFrame,
        texMusicOff: cc.SpriteFrame,
    },

    // use this for initialization
    onLoad: function () {
        if (cc.sys.platform === cc.sys.WECHAT_GAME)
         {
            wx.showShareMenu();

            wx.onShareAppMessage(function () {
                // 用户点击了“转发”按钮
                return {
                  title: '[微信红包]谁能玩通关？考验智力的时候到了！',
                  imageUrl: "http://thyrsi.com/t6/361/1535097085x-1376440174.jpg"
                }
              });
        }
        this.audioMng = this.audioMng.getComponent('AudioMng');
        /*
        if (isMusicOn == false)
        {
            isMusicOn = true;
            this.audioMng.playMusic();
        }*/
        
        //this.SpriteRankingList.Node.active = false;
        cc.director.preloadScene('maingame', function () {
            cc.log('Next scene preloaded');
        });
    },

    // use this for initialization
    init: function (betDuration) {
        this.SpriteRankingList.active = false;
    },

    playGame: function () {
        cc.director.loadScene('maingame');//('maingame');
    },
    showRankingList: function () {
        //cc.director.loadScene('table');
        this.SpriteRankingList.active = true;  
    },

    onButtonClicked: function(){
        if (cc.sys.platform === cc.sys.WECHAT_GAME) {
            wx.shareAppMessage({
              title: '我要主动拉起分享啦',
              success: function(shareTickets,groupMsgInfos){console.log('主动成功')},
              fail: function(res){console.log('主动失败');console.log(res);},
            });

            //wx.clearStorageSync();
        }
    },

    OnButtonCustomerClicked: function(){
        if (cc.sys.platform == cc.sys.WECHAT_GAME){
            wx.openCustomerServiceConversation(
                {
                    sessionFrom: '火柴谜题',
                    showMessageCard: false,	
                    sendMessageTitle: '这是一个会话内消息卡片标题',
                    sendMessagePath: '会话内消息路径',
                    sendMessageImg: '会话内消息卡片图片路径',
                    success:function(){console.log('客服调用成功')},	
                    fail:function(){console.log('接口调用失败的回调函数')},
                    complete:function(){console.log('回调函数')},
                }
            )
        }
    },

    // 音乐开关
    OnButtonMucsicClicked:function(){
        isMusicOn = !isMusicOn;
        if (isMusicOn == false)
        {
            this.audioMng.stopMusic();
            this.btnMusic.spriteFrame = this.texMusicOff;
        }
        else
        {
            this.audioMng.playMusic();
            this.btnMusic.spriteFrame = this.texMusicOn;
        }
    },

    // called every frame
    update: function (dt) {

    },
});
